package com.redteam.data.beans;

import com.redteam.data.enums.FuelAgreement;
import com.redteam.data.enums.RentalTime;
import com.redteam.data.enums.ReservationState;
import java.io.Serializable;
import java.sql.Date;
import java.sql.Time;

/**
 * Class that contains methods for implementing a <code>Reservation</code>
 * @author Jezreel Wilson
 */
public final class Reservation implements Serializable {

    private long id;
    private Person reserver;
    private RentalItem rentalItem;
    private Pilot pilot;
    private Date startDate;
    private Date endDate;
    private Time startTime;
    private Time endTime;
    private ReservationState reservationState;
    private double price;
    private FuelAgreement agreement;
    private String discriminator;
    private RentalTime rentalTime;
    private static final long serialVersionUID = 1L;

    /**
     *Default constructor
     */
    public Reservation() {
        this.setRentalItem(new RentalItem());
        this.setPilot(new Pilot());
        this.setReserver(new Person());

    }

    /**
     * Reservation full constructor
     * @param id
     * @param reserverID
     * @param rentalItemId
     * @param pilotID
     * @param startDate
     * @param endDate
     * @param startTime
     * @param endTime
     * @param price
     * @param reservationState
     * @param agreement
     * @param discriminator
     * @param rentalTime
     */
    public Reservation(long id, Person reserver, RentalItem rentalItem, Pilot pilot, Date startDate, Date endDate, Time startTime, Time endTime, double price, String reservationState, String agreement, String discriminator, String rentalTime) {
        this.setId(id);

        this.setReserver(reserver);
        this.setRentalItem(rentalItem);
        this.setPilot(pilot);
        this.setStartDate(startDate);
        this.setEndDate(endDate);
        this.setStartDate(startDate);
        this.setEndTime(endTime);
        this.setReservationState(reservationState);
        this.setPrice(price);
        this.setAgreement(agreement);
        this.setDiscriminator(discriminator);
        this.setRentalTime(rentalTime);
    }

    /**
     * Returns the reservation's end date
     * @return endDate
     */
    public Date getEndDate() {
        return endDate;
    }

    /**
     * Sets the reservation end date
     * @param endDate
     */
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    /**
     * Returns the reservation's end time
     * @return endTime
     */
    public Time getEndTime() {
        return endTime;
    }

    /**
     * Sets the reservation end time
     * @param endTime
     */
    public void setEndTime(Time endTime) {
        this.endTime = endTime;
    }

    /**
     * Returns reservation's id
     * @return id
     */
    public long getId() {
        return id;
    }

    /**
     * Sets the reservation id
     * @param id
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * Returns the pilot associated with the reservation
     * @return pilot
     */
    public Pilot getPilot() {
        return pilot;
    }

    /**
     * Sets the pilot associated with that reservation
     * @param pilot
     */
    public void setPilot(Pilot pilot) {
        this.pilot = pilot;
    }

    /**
     * Returns the rental items on that reservation
     * @return rentalItem
     */
    public RentalItem getRentalItem() {
        return rentalItem;
    }

    /**
     * Sets the rental items for that reservation
     * @param rentalItemId
     */
    public void setRentalItem(RentalItem rentalItem) {
        this.rentalItem = rentalItem;
    }

    /**
     * Returns the state of the reservation
     * @return reservationState
     */
    public String getReservationState() {
        return reservationState.getLetterRep();
    }

    /**
     * Sets the reservation state
     * @param reservationState
     */
    public void setReservationState(String reservationState) {
        this.reservationState = ReservationState.valueOf(reservationState);
    }

    /**
     * Returns the reserver associated with the reservation
     * @return reserver
     */
    public Person getReserver() {
        return reserver;
    }

    /**
     * Sets the reserver associated with that reservation
     * @param reserver
     */
    public void setReserver(Person reserver) {
        this.reserver = reserver;
    }

    /**
     * Returns the reservation's start date
     * @return startDate
     */
    public Date getStartDate() {
        return startDate;
    }

    /**
     * Sets the reservation start date
     * @param startDate
     */
    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    /**
     * Returns the reservation's start time
     * @return startTime
     */
    public Time getStartTime() {
        return startTime;
    }

    /**
     * Sets the reservation's start time
     * @param startTime
     */
    public void setStartTime(Time startTime) {
        this.startTime = startTime;
    }

    /**
     * Returns the price associate with the reservation
     * @return price
     */
    public double getPrice() {
        return price;
    }

    /**
     * Sets the price for that reservation
     * @param price
     */
    public void setPrice(double price) {
        this.price = price;
    }

    /**
     * Returns the fuel agreement
     * @return agreement
     */
    public String getAgreement() {
        return agreement.getName();
    }

    /**
     * Sets the fuel agreement
     * @param agreement the agreement to set
     */
    public void setAgreement(String agreement) {
        this.agreement = FuelAgreement.valueOf(agreement);
    }

    /**
     * Returns the discriminator of the reservation
     * @return discriminator
     */
    public String getDiscriminator() {
        return discriminator;
    }

    /**
     * Sets the discriminator for the reservation
     * @param discriminator
     */
    public void setDiscriminator(String discriminator) {
        this.discriminator = discriminator;
    }

    /**
     * Returns the rental time type for the reservation
     * @return rentalTime
     */
    public RentalTime getRentalTime() {
        return rentalTime;
    }

    /**
     * Sets the rental time type for the reservation
     * @param rentalTime
     */
    public void setRentalTime(String rentalTime) {
        this.rentalTime = RentalTime.valueOf(rentalTime);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Reservation other = (Reservation) obj;
        if (this.id != other.id) {
            return false;
        }
        if (this.reserver != other.reserver && (this.reserver == null || !this.reserver.equals(other.reserver))) {
            return false;
        }
        if (this.rentalItem != other.rentalItem && (this.rentalItem == null || !this.rentalItem.equals(other.rentalItem))) {
            return false;
        }
        if (this.pilot != other.pilot && (this.pilot == null || !this.pilot.equals(other.pilot))) {
            return false;
        }
        if (this.startDate != other.startDate && (this.startDate == null || !this.startDate.equals(other.startDate))) {
            return false;
        }
        if (this.endDate != other.endDate && (this.endDate == null || !this.endDate.equals(other.endDate))) {
            return false;
        }
        if (this.startTime != other.startTime && (this.startTime == null || !this.startTime.equals(other.startTime))) {
            return false;
        }
        if (this.endTime != other.endTime && (this.endTime == null || !this.endTime.equals(other.endTime))) {
            return false;
        }
        if (this.reservationState != other.reservationState) {
            return false;
        }
        if (Double.doubleToLongBits(this.price) != Double.doubleToLongBits(other.price)) {
            return false;
        }
        if (this.agreement != other.agreement) {
            return false;
        }
        if ((this.discriminator == null) ? (other.discriminator != null) : !this.discriminator.equals(other.discriminator)) {
            return false;
        }
        if (this.rentalTime != other.rentalTime) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 53 * hash + (int) (this.id ^ (this.id >>> 32));
        hash = 53 * hash + (this.reserver != null ? this.reserver.hashCode() : 0);
        hash = 53 * hash + (this.rentalItem != null ? this.rentalItem.hashCode() : 0);
        hash = 53 * hash + (this.pilot != null ? this.pilot.hashCode() : 0);
        hash = 53 * hash + (this.startDate != null ? this.startDate.hashCode() : 0);
        hash = 53 * hash + (this.endDate != null ? this.endDate.hashCode() : 0);
        hash = 53 * hash + (this.startTime != null ? this.startTime.hashCode() : 0);
        hash = 53 * hash + (this.endTime != null ? this.endTime.hashCode() : 0);
        hash = 53 * hash + (this.reservationState != null ? this.reservationState.hashCode() : 0);
        hash = 53 * hash + (int) (Double.doubleToLongBits(this.price) ^ (Double.doubleToLongBits(this.price) >>> 32));
        hash = 53 * hash + (this.agreement != null ? this.agreement.hashCode() : 0);
        hash = 53 * hash + (this.discriminator != null ? this.discriminator.hashCode() : 0);
        hash = 53 * hash + (this.rentalTime != null ? this.rentalTime.hashCode() : 0);
        return hash;
    }
}
